/*
 * 百度在线网络技术（北京）有限公司拥有本软件版权2020并保留所有权利。
 * Copyright 2020, Baidu.com,Inc 2:Baidu Online Network Technology (Beijing) Co.,Ltd,
 * All rights reserved.
 */

package com.azdebugit.moshi.test.learn.proxy.jdkproxy;

import com.azdebugit.moshi.test.learn.proxy.jing1.ISubject;
import com.azdebugit.moshi.test.learn.proxy.jing1.SubjectImpl;
import com.azdebugit.moshi.test.learn.proxy.jing2.IUpdatable;
import com.azdebugit.moshi.test.learn.proxy.jing2.UpdatableImpl;
import org.junit.Test;

import java.lang.reflect.Proxy;

public class Client {
  @Test
  public void testDynamicProxy() {
    ISubject subject = new SubjectImpl();
    ISubject proxySubject = (ISubject) Proxy.newProxyInstance(Client.class.getClassLoader(), new Class[]{ISubject.class}, new SafetyInvocationHandler(subject));
    proxySubject.request();

    IUpdatable updatable = new UpdatableImpl();
    IUpdatable proxyUpdatable = (IUpdatable) Proxy.newProxyInstance(Client.class.getClassLoader(), new Class[]{IUpdatable.class}, new SafetyInvocationHandler(updatable));
    proxyUpdatable.update();
  }
}